#include <iostream>
#include "EventBusLite.h"

using namespace std;

struct Functor : public Observer
{
    void operator()(int msgid, void **pUser)
    {
        int **data = (int **)pUser;
        cout << "functor.operator() :" << msgid << " user data: " << **data << endl;
        ++(**data);
    }
};

void handler(int msgid, void **pUser)
{
    int **data = (int **)pUser;
    cout << "handler :" << msgid << " user data: " << **data << endl;
    **data = 20;
}

int main(int argc, char *argv[])
{
    int a = 1;
    int *pa = &a;
    ge_attach(1, handler);
    ge_notify(1, (void **)(&pa));
    cout << "after " << a << endl;

    ge_detach(1, handler);

    a = 30;
    Functor functor;
    ge_attach(1, &functor);
    ge_notify(1, (void **)(&pa));
    cout << "after class functor " << a << endl;

    return 0;
}